# 自建HashTable类


class HashTable:
    def __init__(self, size=11) -> None:
        self.size = 11
        self.throw = [None] * size
        self.data = [None] * size

    def put(self, key, value):
        hash_key = self.__hash_f(key)
        self.throw[hash_key] = key
        self.data[hash_key] = value


    def __hash_f(self, key):
        return key % self.size

    def get(self, key):
        hash_key = self.__hash_f(key)
        return self.data[hash_key]

    def __str__(self):
        result = ''
        for i in range(self.size):
            if self.throw[i]:
                result += f'{self.throw[i]} : {self.data[i]} | '
        return result[0:-2]

    def __getitem__(self, key):
        return self.get(key)

    def __setitem__(self, key, value):
        return self.put(key,value)


if __name__ == '__main__':
    hash_table = HashTable()
    hash_table.put(26, 'Nasa')
    hash_table.put(21, 'zhao')
    hash_table[1] = 'lin'
    v = hash_table.get(21)
    print(hash_table)
    print(v)
    print(hash_table[26])
